﻿@using Kevin.Shop.Business.Service.Entity.Helper
@model  RiderShop.Mobile.Modle.MyAccount.MyPointModel
@section title
{
    鲜粉签到簿，礼尚往来
}
@section pagetitle
{
    鲜粉签到簿，礼尚往来
}
@section header
{
    <link href="~/Themes/RongJi/Style/point/css/style.css" rel="stylesheet" />
    <style>
        body {
            overflow: auto !important;
            background-color: #8affab;
        }

        .pageHeaderMini {
            display: none;
        }

        .checkin-main {
            min-height: 370px;
        }
    </style>
}


@{
    int consecutiveDays = 0;
    bool isCheckInToday = false;
    if (Model.PointList != null)
    {
        var dateCheck = DateTime.Now.AddDays(-1);
        Model.PointList = Model.PointList.OrderByDescending(p => p.TradeDate).ToList();
        foreach (var point in Model.PointList)
        {
            if (point.TradeDate.ToShortDateString() == DateTime.Now.ToShortDateString())
            {
                isCheckInToday = true;
                consecutiveDays++;
            }
            else
            {
                if (point.TradeDate.ToShortDateString() == dateCheck.ToShortDateString() && point.Mark == 0
                    && consecutiveDays <= 7)
                {
                    consecutiveDays++;
                }
                else
                {
                    break;
                }
                dateCheck = dateCheck.AddDays(-1);
            }
        }
    }
}

<div class="checkin-wrapper">
    <header class="checkin-header">
        <img src="~/Themes/RongJi/Style/point/images/aa.jpg" class="weixin-avarta">
        @if (string.IsNullOrEmpty(WebClientContext.Current.CurrentUser.HeadImgUrl))
        {
            <img src="~/Themes/RongJi/Style/base/imgs/default-res-usercenter_head.png" class="weixin-avarta" />
        }
        else
        {
            <img src="@WebClientContext.Current.CurrentUser.HeadImgUrl" class="weixin-avarta" />
        }
        <dl>
            <dt>@WebClientContext.Current.CurrentUser.RealName</dt>
            <dd id="usePoints">积分 @WebClientContext.Current.CurrentUser.Points</dd>
        </dl>
        <div class="checkin-rules">
            <script>
                var d = new Date()
                document.write(d.getDate())
            </script>
        </div>
        <div class="show-rules">查看规则</div>
    </header>
    <div class="checkin-main">
        <div class="checkin-days">
            <img src="~/Themes/RongJi/Style/point/images/checkin_day.png">
            <div class="my-days">
                <div class="my-days-wrapper">
                    <span>
                        <h3>已连续签到</h3>
                        <p><em id="consecutiveDaysShow">@consecutiveDays</em>天</p>
                        @if (isCheckInToday)
                        {
                            <div class="checkin-btn" id="btnHasChecked">
                                <img src="~/Themes/RongJi/Style/point/images/hascheckin-btn.png" />
                            </div>
                        }
                        else
                        {
                            <div class="checkin-btn" id="btnCheckIn">
                                <img src="~/Themes/RongJi/Style/point/images/checkin-btn.png">
                            </div>
                        }
                    </span>
                </div>
            </div>
        </div>
        <div class="checkin-tracker">
            <div class="checkin-tracker-bar">
                <input type="hidden" id="consecutiveDays" value="@consecutiveDays" />
                <input type="hidden" id="isCheckInToday" value="@(isCheckInToday?1:0)" />
                <ol id="checkInList">
                    @for (int i = 1; i <= 7; i++)
                    {
                        if (i == consecutiveDays)
                        {
                            <li class="checkin-tracker-bar-point has-checkedin">
                                <span class="check-mark">
                                    <div class='pin'></div><img src="~/Themes/RongJi/Style/point/images/xian.png">
                                </span>
                                <span class="check-num">@i</span>
                                @if (i == 7)
                                {
                                    <a href="javascript:void(0)" id="getGift" class="giftbox animated pulse infinite">签到礼包</a>
                                }
                            </li>
                        }
                        else
                        {
                            <li class="checkin-tracker-bar-point">
                                <span class="check-mark">
                                    <div class='pin'></div><img src="~/Themes/RongJi/Style/point/images/xian.png">
                                </span>
                                <span class="check-num">@i</span>
                                @if (i == 7)
                                {
                                    <a href="javascript:void(0)" id="getGift" class="giftbox animated pulse infinite">签到礼包</a>
                                }
                            </li>
                        }
                    }
                </ol>

            </div>
        </div>
    </div>
   
</div>
<div class="rules-wrapper">
    <div class="rules">
        <dl>
            <dt>签到说明</dt>
            <dd>&nbsp;&nbsp;&nbsp;&nbsp;签到一次获得1个鲜豆，连续签到7天获得一次抽取礼包机会。中途中断则重新开始计算连续签到天数，每七天一个周期。</dd>
            <dd>&nbsp;&nbsp;&nbsp;&nbsp;鲜豆可以购买商品也可以参加网站活动，福利多多，快快行动吧</dd>
            <dt>签到规则</dt>
            <dd>1. 每签到一次获得1个鲜豆奖励。</dd>
            <dd>2. 连续签到7天获得一次抽取礼包机会。礼包内容：10鲜豆,5元优惠券,10元优惠券,20元优惠券,30元优惠券。</dd>
            <dd>3. 连续签到7天后重新开始计算连续签到天数。</dd>
        </dl>
        <img src="~/Themes/RongJi/Style/point/images/zhidaole.png" width="130" class="close-tips">
    </div>
</div>
<div class="checkin-success-wrapper">
    <div class="checkin-success">
        <p id="checkMsg">签到成功</p>
        <img src="~/Themes/RongJi/Style/point/images/zhidaole.png" width="130" class="close-tips">
    </div>
</div>




@section footer
{
    <script type="text/javascript">
        $(function () {

            //让toolbar选中
            var $homeImg = $("#homeImg");
            var $categoryImg = $("#categoryImg");
            var $myaccountImg = $("#myaccountImg");
            var $searchImg = $("#searchImg");
            $homeImg.attr("src", "/Themes/RongJi/Style/base/imgs/f10.png");
            $categoryImg.attr("src", "/Themes/RongJi/Style/base/imgs/f2.png");
            $myaccountImg.attr("src", "/Themes/RongJi/Style/base/imgs/f3_c.png");
            $searchImg.attr("src", "/Themes/RongJi/Style/base/imgs/f4.png");


            $('.show-rules').on('click', function () {
                $('.rules-wrapper').show();
            })

            var isChecking = false;
            var hasChecked = false;
            $('#btnCheckIn').on('click', function () {
                if (hasChecked) {
                    showMessage("亲，不要在点啦，您今天已经签过啦。");
                    return;
                }
                if (isChecking) {
                    return;
                }
                isChecking = true;
                KevinShop.Common.Ajax.Post('PointUserCheckIn', [], function (data) {
                    if (data.Status) {


                        var consecutiveDays = parseInt($('#consecutiveDays').val());
                        if (consecutiveDays == 6) {
                            showMessage("亲，恭喜您，完成本轮签到！您获得了领取礼包的机会，快快领取吧^_^。");
                        }
                        else {
                            showMessage("签到成功");
                        }

                        $('#usePoints').html('积分 ' + data.Tag);


                        moveCheckIn();
                    }
                    else {
                        showMessage("亲，不要在点啦，您今天已经签过啦。");
                    }
                    hasChecked = true;

                })

            });

            $('#btnHasChecked').on('click', function () {
                showMessage("亲，不要在点啦，您今天已经签过啦。");
            });

            $('#getGift').on('click', function () {

                window.location.href = 'PointCheckInRewards';

                //var consecutiveDays = parseInt($('#consecutiveDays').val());
                //var isCheckInToday = parseInt($('#isCheckInToday').val());
                //if (consecutiveDays === 7) {
                //    getBigGift();
                //}
                //else if (consecutiveDays === 6) {
                //    if (!isCheckInToday) {
                //        if (hasChecked) {
                //            getBigGift();
                //        }
                //        else {
                //            showMessage("点击签到就能获取礼包了。");
                //        }
                //    }
                //    else {
                //        if (hasChecked) {
                //            showMessage("继续努力，明天你就可以获取签到礼包。");
                //        }
                //        else {
                //            showMessage("继续努力，第七天你就可以获取签到礼包。");
                //        }
                //    }
                //}
                //else {
                //    showMessage("继续努力，第七天你就可以获取签到礼包。");
                //}

            });

            function getBigGift() {
                $.get("PointCheckInRewards", function (data) {
                    showMessage(data.ErrorMessage);
                });
            }

            function showMessage(msg) {
                $("#checkMsg").html(msg);
                $('.checkin-success-wrapper').show();
            }

            function moveCheckIn() {
                var consecutiveDays = parseInt($('#consecutiveDays').val());

                var checkInList = $('#checkInList');
                var consecutiveDaysShow = $('#consecutiveDaysShow');
                consecutiveDaysShow.text(parseInt(consecutiveDaysShow.text()) + 1);

                if (consecutiveDays === 0) {
                    checkInList.children().eq(0).addClass('has-checkedin');
                }
                else {
                    checkInList.children().eq(consecutiveDays - 1).removeClass('has-checkedin');
                    checkInList.children().eq(consecutiveDays).addClass('has-checkedin');
                }

                $('#btnCheckIn').html('<img src="/Themes/RongJi/Style/point/images/hascheckin-btn.png" />');
            }


            $('.close-tips').on('click', function () {
                $('.checkin-success-wrapper').hide();
                $('.rules-wrapper').hide();
            })


            //分享
            window.config.link = 'http://m.rongji365.com/myaccount/pointcheckin';
            window.config.desc = '鲜粉足迹，签到送礼。品质生活，服务专家。';
            window.config.title = '【鲜粉签到簿，礼尚往来】';
            window.config.imgUrl = 'http://m.rongji365.com/Storage/CommResource/sicon.jpg';
            window.config.img_url = 'http://m.rongji365.com/Storage/CommResource/sicon.jpg';//兼容老微信

        });
    </script>
}


